//
// Created by none98 on 2021/9/14.
//

#ifndef LOGINSERVER_TIMER_H
#define LOGINSERVER_TIMER_H

#include "CallBacks.h"
#include "TimeStamp.h"

class Timer {
    friend class TimerEventQueue;
public:
    Timer(const TimeStamp &time, const TimerCallBack &callBack, bool isCycle, int fd):
        interval(time),
        callBack(callBack),
        isCycle(isCycle),
        expire(TimeStamp::NowTime()+time),
        fd(fd)
    {
    }

    ~Timer() = default;


    bool operator<(const Timer &timer)const{
        return expire<timer.expire;
    }

    bool operator>(const Timer &timer)const{
        return expire>timer.expire;
    }

    void SetCircular(bool isCycle){
        this->isCycle = isCycle;
    }

    int GetFdOfTimer()const{
        return fd;
    }

private:
    void SetExpire(const TimeStamp &expiredTime){
        expire = expiredTime;
    }

    TimeStamp GetExpire() const{
        return expire;
    }

    TimeStamp GetInterval()const{
        return interval;
    }

    bool IsCircular() const{
        return isCycle;
    }

private:
    TimerCallBack callBack;
    TimeStamp interval;
    TimeStamp expire;
    bool isCycle;
    int fd;
};



#endif //LOGINSERVER_TIMER_H
